package com.hxrd.androidprint.DBUtils;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

/**
 * Created by zhang on 16/11/23.
 */
public class DBOpenHelper extends SQLiteOpenHelper {

    //数据库文件的名字
    public static String DATABASE_NAME = "PepsiCoataBase.db";

    //数据库 表名
    /*public static String TABLE_ONE = "WMS_SC_Single";
    public static String TABLE_TWO = "WMS_SC_Single_DetailBean";
    public static String TABLE_THREE = "WMS_SC_Single_Detail_QRCode";*/
    public static String DETAIL_TAB = "detail";
    public static String SEND_GOODS_CODE_TAB = "sendGoodsCode";
    public static String SCAN_CODE_TAB = "scanCode";
    public static String PRINT_TAB="print";
    public static String CHANGE_URL="url";

    /**
     * 构造方法
     * @param context
     * @param name
     * @param factory
     * @param version
     */
    public DBOpenHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    /**
     * onCreate 方法  第一次创建的时候的回调方法
     * @param sqLiteDatabase
     */
    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {

        String sqlDetail= "create table "+DETAIL_TAB +
                " (Order_Code text," +
                "WMSD_Code text, " +
                "ERP_DCode text, " +
                "Shipper_Code text, " +
                "Ship_Code text, "+
                "ERP_Product_Code text, "+
                "Product_Name text, "+
                "Pack_QTY text, "+
                "FactoryName text, "+
                "WareHouse_Code text, "+
                "ScanCount text,"+
                "Plan_Outbound_Time text,"+
                "is_has_code text)";

        String sqlSendGoodsCode= "create table "+SEND_GOODS_CODE_TAB +
                " (id integer primary key autoincrement, " +
                "Order_Code text,"+
                "Send_State text)";// 0代表没有界面扫描，1代表已经有界面扫描

        String sqlScanCode= "create table "+SCAN_CODE_TAB +
                " (id integer primary key autoincrement, " +
                "Order_Code text,"+
                "Car_Name text,"+
                "WMSD_Code text,"+
                "ERP_Product_Code text,"+
                "BackCode text,"+
                "CodeCount text,"+
                "types text,"+
                "is_has_code text)";

        String sqlPrint= "create table "+PRINT_TAB +
                " (id integer primary key autoincrement, " +
                "WMSD_Code text,"+
                "Product_Name text,"+
                "Duo_Count text,"+
                "San_Count text,"+
                "Send_Name text,"+
                "ERP_DCode text,"+
                "Order_Code text,"+
                "Car_Name text,"+
                "ERP_Product_Code text)";




        String sqlUrl= "create table "+CHANGE_URL +
                " (id integer primary key autoincrement, " +
                "url text)";

        //操作数据库 执行SQL语句
        sqLiteDatabase.execSQL(sqlDetail);
        sqLiteDatabase.execSQL(sqlSendGoodsCode);
        sqLiteDatabase.execSQL(sqlScanCode);
        sqLiteDatabase.execSQL(sqlPrint);
        sqLiteDatabase.execSQL(sqlUrl);


    }

    /**
     * onUpgrade 方法  当数据库版本更新的时候的回调方法
     * @param sqLiteDatabase
     * @param oldVersion
     * @param newVersion
     */

    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {

    }
}
